#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void lower(char *str);

int main()
{
    char s[101];
    scanf("%s", s);
    lower(s);
    int slen = strlen(s);

    int len;
    scanf("%d", &len);

    char(*strs)[101];
    strs = (char(*)[101])malloc(sizeof(char[101]) * len);
    for (int i = 0; i < len; i++)
    {
        scanf("%s", strs[i]);
    }

    char tempchar;
    char *ptr;
    char tempstr[101];
    for (int i = 0; i < len; i++)
    {
        strcpy(tempstr, strs[i]);
        lower(tempstr);
        for (ptr = tempstr; ptr[slen - 1] != 0; ptr++)
        {
            tempchar = ptr[slen];
            ptr[slen] = 0;
            if (strcmp(s, ptr) == 0)
            {
                printf("%s\n", strs[i]);
                break;
            }
            ptr[slen] = tempchar;
        }
    }
}

void lower(char *str)
{
    while (*str)
    {
        if (*str >= 'A' && *str <= 'Z')
        {
            *str += 'a' - 'A';
        }
        str++;
    }
}
